#include "debug.h"
#include <SDL/SDL_image.h>
#include "Elements\\Image.h"

using namespace SDL::UTILS;

NS_BEGIN(SDL)
NS_BEGIN(ELEMENTS)

#pragma region CTOR & DTOR

Image::Image(std::string const& _path)
	: AElement(), m_path(_path), m_rect()
{
	CTOR("Image", this);
	m_surface = new Surface(IMG_Load(_path.c_str()));
}

Image::Image(Image const& _image) : AElement(*((AElement*)&_image))
{
	CTOR("Image", this);
	*this = _image;
}

Image::~Image()
{
	DTOR("Image", this);
}

#pragma endregion
#pragma region Operators

Image& Image::operator=(Image const& _image)
{
	if (this != &_image)
	{
		*((AElement*)this) = *((AElement*)&_image);
		m_path = _image.GetPath();
		m_rect = _image.GetRect();
	}
	return (*this);
}

bool Image::operator==(Image const& _image) const
{
	return ((AElement*)this == (AElement*)&_image &&
			m_path == _image.GetPath() && m_rect == _image.GetRect());
}

bool Image::operator!=(Image const& _image) const
{
	return ((AElement*)this != (AElement*)&_image ||
			m_path != _image.GetPath() || m_rect != _image.GetRect());
}

#pragma endregion

bool Image::Draw(SDL_Surface* _screen)
{
	if (m_hidden == false)
	{
		if (m_surface != NULL)
			m_surface->BlitSurface(&m_rect, _screen, &m_position);
		else
			return (false);
	}
	return (true);
}

void Image::SetPosition(Sint16 _x, Sint16 _y)
{
	m_position.SetX(_x);
	m_position.SetY(_y);
}

void Image::SetPosition(Rect const& _position)
{
	m_position = _position;
}

void Image::Move(Sint16 _offsetX, Sint16 _offsetY)
{
	m_position.SetX(m_position.GetX() + _offsetX);
	m_position.SetY(m_position.GetY() + _offsetY);
}

void Image::Move(Rect const& _offset)
{
	m_position.SetX(m_position.GetX() + _offset.GetX());
	m_position.SetY(m_position.GetY() + _offset.GetY());
}

#pragma region Getters & Setters

std::string const& Image::GetPath() const
{
	return (m_path);
}

Rect const& Image::GetRect() const
{
	return (m_rect);
}

void Image::SetRect(Rect const& _rect)
{
	m_rect = _rect;
}

#pragma endregion

NS_END(ELEMENTS)
NS_END(SDL)
